package cn.ycc1.mymiddle.functioncalling;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ycc
 * @date 2025/5/1
 */
@RestController
@RequestMapping("/function-calling")
public class FunctionCallController {

    private final ChatClient chatClient;
    public FunctionCallController(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    @GetMapping("/chat")
    public String chat(String input) {
        ChatResponse response = this.chatClient.prompt()
                .functions("currentWeather")
                // .user("What's the weather like in San Francisco, Tokyo, and Paris?")
                .user("Use the 'currentWeather' function to get weather for Shanghai.")
                .call()
                .chatResponse();

        System.out.println(response);
        return response.toString();
    }
}
